package net.mikoo.seals.api.model.use;

import java.text.SimpleDateFormat;

import net.mikoo.seals.api.model.BaseResponse;
import net.mikoo.seals.model.DevicesAct;

public class UseDetailResponse extends BaseResponse {

	private static final long serialVersionUID = -3398756461429381328L;
	
	private Long id;
	
	private String devicesName;
	
	private String devicesNo;
	
	private String partyName;
	
	private Long partyId;
	
	private Long devicesId;
	
	private Integer total;
	
	private Integer surplus;
	
	private String startTime;
	
	private String endTime;
	
	private String expireTime;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDevicesName() {
		return devicesName;
	}

	public void setDevicesName(String devicesName) {
		this.devicesName = devicesName;
	}
	
	public String getDevicesNo() {
		return devicesNo;
	}

	public void setDevicesNo(String devicesNo) {
		this.devicesNo = devicesNo;
	}

	public String getPartyName() {
		return partyName;
	}

	public void setPartyName(String partyName) {
		this.partyName = partyName;
	}

	public Integer getTotal() {
		return total;
	}

	public void setTotal(Integer total) {
		this.total = total;
	}

	public Integer getSurplus() {
		return surplus;
	}

	public void setSurplus(Integer surplus) {
		this.surplus = surplus;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public String getExpireTime() {
		return expireTime;
	}

	public void setExpireTime(String expireTime) {
		this.expireTime = expireTime;
	}
	
	public Long getPartyId() {
		return partyId;
	}

	public void setPartyId(Long partyId) {
		this.partyId = partyId;
	}

	public Long getDevicesId() {
		return devicesId;
	}

	public void setDevicesId(Long devicesId) {
		this.devicesId = devicesId;
	}

	public static UseDetailResponse valueOf(DevicesAct act) {
		UseDetailResponse result = new UseDetailResponse();
		
		if(act == null) {
			return result;
		}
		
		result.setId(act.getDevicesActId());
		result.setDevicesName(act.getDevices().getAlias());
		result.setDevicesNo(act.getDevices().getDevicesCode());
		result.setTotal(act.getTotalTimes());
		result.setSurplus(act.getTotalTimes() - act.getUseTimes());
		
		result.setDevicesId(act.getDevicesId());
		result.setPartyId(act.getPartyId());
		
		if(act.getInvalidTime() != null) {
			result.setExpireTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(act.getInvalidTime()));
		}
		return result;
	}
}
